//use std::io::stdin;
use std::fs;
use std::io::prelude::*;
use std::fs::File;
use std::collections::HashMap;

fn main() {
    //输入
    /*let mut str_buf = String::new();
    stdin().read_line(&mut str_buf)
        .expect("Failed to read line.");
    println!("Your input line is \n{}", str_buf);*/
    
    //读取
    //let text = fs::read_to_string("text.txt").unwrap();
    //println!("{}", text);
    
    //文件流读取
    let mut buffer = [0u8; 5];
    let mut file = fs::File::open("text.txt").unwrap();
    file.read(&mut buffer).unwrap();
    println!("{:?}", buffer);
    file.read(&mut buffer).unwrap();
    println!("{:?}", buffer);

    //写入
    fs::write("one.txt", "FROM RUST PROGRAM CARRY!")
        .unwrap();
    
    //文件流写入
    let mut file = File::create("one.txt").unwrap();
    file.write(b"FROM RUST PROGRAM").unwrap();

    let s = String::from("hello中文");
    for c in s.chars() {
        println!("{}", c);
    }
    
    let s1 = String::from("EN中文");
    let a = s1.chars().nth(2);
    println!("{:?}", a);

    let mut map = HashMap::new();

    map.insert("color", "red");
    map.insert("size", "10 m^2");

    println!("{} {}", map.get("color").unwrap(), map.get("size").unwrap());

    for p in map.iter() {
        println!("{:?}", p);
    }
}


































